//
// Created by 32827 on 2024/2/1.
//
#include "view/yzl_ui_view_pp_demo.hpp"

YZF_RESULT user_ui_info(){
//    yzf_area_recv_add(yz_recv_transmit_area_get(),0x06);
//    yzf_area_recv_add(yz_recv_transmit_area_get(),0x00);
//    yzf_area_recv_add(yz_recv_transmit_area_get(),0x00);
//    yzf_area_recv_add(yz_recv_transmit_area_get(),0x00);
    return YZF_OK;
}
void test_listener(void *widget, YZL_UI_CTR_EVENT event){
    if(event==YZL_UI_CTR_EVENT_TOUCH_UP){
        yzf_global_handler_add(user_ui_info);
    }
}

//-----------------------------------------------------------------------

ViewDemo::ViewDemo(YZL_VIEW *viewRam, char *logoPath,char *personPath): ViewBase(viewRam) {
    this->logoPath = logoPath;
    this->personPath = personPath;
}

ViewDemo::~ViewDemo() = default;

YZF_BOOL ViewDemo::initP(void *initStructPointer, void *actStructPointer) {
    ViewBase::initP(initStructPointer, actStructPointer);

    mButton1=new WidgetButton((*this)[-1],400-(YZL_FONT_SIZE*4+80)/2,160+240, 0,YZL_FONT_SIZE*4+80, YZL_FONT_LINE_HEIGHT*2,
                              (utf8 *) "点击开始");
    addChild(mButton1);

    mButton2=new WidgetButton((*this)[-1],400-(YZL_FONT_SIZE*4+80)/2,160+240+YZL_FONT_LINE_HEIGHT*2, 0,YZL_FONT_SIZE*4+80, YZL_FONT_LINE_HEIGHT*2,
                              (utf8 *) "外设控制");
    addChild(mButton2);

    mText1=new WidgetText((*this)[-1],10, 240,0,YZL_FONT_SIZE*10+80, YZL_FONT_LINE_HEIGHT*4,
                          (utf8 *) "文本");
    addChild(mText1);
    mButton1->setListener(test_listener);

    return YZF_TRUE;
}

char *ViewDemo::getViewName() {
    return "ViewDemo";
}

int ViewDemo::getViewId() {
    return 1;
}

void ViewDemo::wakeupP(void *actStructPointer) {
    yzl_ui_fill_screen(BLACK);
    yzl_ui_draw_img(logoPath,(800-320)/2,(480-320)/2,320,320);
    yzl_ui_draw_565a(personPath,10,10);
    ViewBase::wakeupP(actStructPointer);
}

